A GOptionArgFunc should return gboolean and take also a GError pointer
authorTor Lillqvist <tml@iki.fi>
Mon, 12 Jan 2009 12:05:13 +0000 (12:05 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Mon, 12 Jan 2009 12:05:13 +0000 (12:05 +0000)
2009-01-12  Tor Lillqvist  <tml@iki.fi>

* gdk/gdk.c (gdk_arg_debug_cb) (gdk_arg_no_debug_cb): A
GOptionArgFunc should return gboolean and take also a GError
pointer parameter, so make these two functions do that. Return
FALSE (and set the GError) if the parsing of the debug string
failed completely. Note that g_parse_debug_string() doesn't really
have any way to return parsing status, and accepts partially
incorrect strings, though.

svn path=/trunk/; revision=22095

ChangeLog
gdk/gdk.c

index 3f282b1d8721d8e55d8c5c7adf50b0c2a5ec7b84..296e06548f3fcbb12804b896e1e04c5ab3cbeebe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-01-12  Tor Lillqvist  <tml@iki.fi>
+
+       * gdk/gdk.c (gdk_arg_debug_cb) (gdk_arg_no_debug_cb): A
+       GOptionArgFunc should return gboolean and take also a GError
+       pointer parameter, so make these two functions do that. Return
+       FALSE (and set the GError) if the parsing of the debug string
+       failed completely. Note that g_parse_debug_string() doesn't really
+       have any way to return parsing status, and accepts partially
+       incorrect strings, though.
+
 2009-01-12  Claudio Saavedra  <csaavedra@igalia.com>
 
        Bug 567468 – no check for trailing != NULL in
index d0ed996cf733da901f1db1a9aaca31362a4d76fc..da5d6335c20bbed4c2341710a42cd6e3a2ddc208 100644 (file)
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -89,20 +89,44 @@ static const int gdk_ndebug_keys = G_N_ELEMENTS (gdk_debug_keys);
 #endif /* G_ENABLE_DEBUG */
 
 #ifdef G_ENABLE_DEBUG
-static void
-gdk_arg_debug_cb (const char *key, const char *value, gpointer user_data)
+static gboolean
+gdk_arg_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
 {
-  _gdk_debug_flags |= g_parse_debug_string (value,
+  guint debug_value = g_parse_debug_string (value,
                                            (GDebugKey *) gdk_debug_keys,
                                            gdk_ndebug_keys);
+
+  if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
+    {
+      g_set_error (error, 
+                  G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                  _("Error parsing option --gdk-debug"));
+      return FALSE;
+    }
+
+  _gdk_debug_flags |= debug_value;
+
+  return TRUE;
 }
 
-static void
-gdk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data)
+static gboolean
+gdk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
 {
-  _gdk_debug_flags &= ~g_parse_debug_string (value,
-                                            (GDebugKey *) gdk_debug_keys,
-                                            gdk_ndebug_keys);
+  guint debug_value = g_parse_debug_string (value,
+                                           (GDebugKey *) gdk_debug_keys,
+                                           gdk_ndebug_keys);
+
+  if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
+    {
+      g_set_error (error, 
+                  G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                  _("Error parsing option --gdk-no-debug"));
+      return FALSE;
+    }
+
+  _gdk_debug_flags &= ~debug_value;
+
+  return TRUE;
 }
 #endif /* G_ENABLE_DEBUG */